{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f262985e-e973-4a27-9c9e-dbb3a06a35b7",
   "metadata": {},
   "source": [
    "# How to define input/output schema for your graph\n",
    "\n",
    "By default, `StateGraph` takes in a single schema and all nodes are expected to communicate with that schema. However, it is also possible to define explicit input and output schemas for a graph. This is helpful if you want to draw a distinction between input and output keys.\n",
    "\n",
    "In this notebook we'll walk through an example of this. At a high level, in order to do this you simply have to pass in separate [`Annotation.Root({})`](https://langchain-ai.github.io/langgraphjs/reference/functions/langgraph.Annotation.Root.html) objects as `{ input: Annotation.Root({}), output: Annotation.Root({}) }` when defining the graph. Let's see an example below!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6ec0eb77-874e-443e-8c73-93125b515106",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{ answer: 'bye' }\n"
     ]
    }
   ],
   "source": [
    "import { Annotation, StateGraph } from \"@langchain/langgraph\";\n",
    "\n",
    "const InputAnnotation = Annotation.Root({\n",
    "  question: Annotation<string>,\n",
    "});\n",
    "\n",
    "const OutputAnnotation = Annotation.Root({\n",
    "  answer: Annotation<string>,\n",
    "});\n",
    "\n",
    "const answerNode = (_state: typeof InputAnnotation.State) => {\n",
    "  return { answer: \"bye\" };\n",
    "};\n",
    "\n",
    "const graph = new StateGraph({\n",
    "  input: InputAnnotation,\n",
    "  output: OutputAnnotation,\n",
    "})\n",
    "  .addNode(\"answerNode\", answerNode)\n",
    "  .addEdge(\"__start__\", \"answerNode\")\n",
    "  .compile();\n",
    "\n",
    "await graph.invoke({\n",
    "  question: \"hi\",\n",
    "});"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a68836f-98e1-4684-a8a6-c1473c73460c",
   "metadata": {},
   "source": [
    "Notice that the output of invoke only includes the output schema."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "TypeScript",
   "language": "typescript",
   "name": "tslab"
  },
  "language_info": {
   "codemirror_mode": {
    "mode": "typescript",
    "name": "javascript",
    "typescript": true
   },
   "file_extension": ".ts",
   "mimetype": "text/typescript",
   "name": "typescript",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
